* read in annual state population data 
* from seer data

clear
*set more off
use state_pop_annual
sort fips year


* do population
rename population x1
by fips: gen xl1=x1[_n+1]
gen dp1=(ln(xl1)-ln(x1))/12
replace dp1=dp1[_n-1] if year==2014
forvalues i=2/24 {
gen x`i'=x1*(exp((dp1)*(`i'-1)))
}
drop dp1 xl1
rename x* population*

* do white_pop
rename white_pop x1
by fips: gen xl1=x1[_n+1]
gen dp1=(ln(xl1)-ln(x1))/12
replace dp1=dp1[_n-1] if year==2014
forvalues i=2/24 {
gen x`i'=x1*(exp((dp1)*(`i'-1)))
}
drop dp1 xl1
rename x* white_pop*

* do black_pop
rename black_pop x1
by fips: gen xl1=x1[_n+1]
gen dp1=(ln(xl1)-ln(x1))/12
replace dp1=dp1[_n-1] if year==2014
forvalues i=2/24 {
gen x`i'=x1*(exp((dp1)*(`i'-1)))
}
drop dp1 xl1
rename x* black_pop*

* do other_pop
rename other_pop x1
by fips: gen xl1=x1[_n+1]
gen dp1=(ln(xl1)-ln(x1))/12
replace dp1=dp1[_n-1] if year==2014
forvalues i=2/24 {
gen x`i'=x1*(exp((dp1)*(`i'-1)))
}
drop dp1 xl1
rename x* other_pop*


* do hispanic_pop
rename hispanic_pop x1
by fips: gen xl1=x1[_n+1]
gen dp1=(ln(xl1)-ln(x1))/12
replace dp1=dp1[_n-1] if year==2014
forvalues i=2/24 {
gen x`i'=x1*(exp((dp1)*(`i'-1)))
}
drop dp1 xl1
rename x* hispanic_pop*

* do agele19_pop
rename agele19_pop x1
by fips: gen xl1=x1[_n+1]
gen dp1=(ln(xl1)-ln(x1))/12
replace dp1=dp1[_n-1] if year==2014
forvalues i=2/24 {
gen x`i'=x1*(exp((dp1)*(`i'-1)))
}
drop dp1 xl1
rename x* agele19_pop*

* do age2034_pop
rename age2034_pop x1
by fips: gen xl1=x1[_n+1]
gen dp1=(ln(xl1)-ln(x1))/12
replace dp1=dp1[_n-1] if year==2014
forvalues i=2/24 {
gen x`i'=x1*(exp((dp1)*(`i'-1)))
}
drop dp1 xl1
rename x* age2034_pop*

* do age3549_pop
rename age3549_pop x1
by fips: gen xl1=x1[_n+1]
gen dp1=(ln(xl1)-ln(x1))/12
replace dp1=dp1[_n-1] if year==2014
forvalues i=2/24 {
gen x`i'=x1*(exp((dp1)*(`i'-1)))
}
drop dp1 xl1
rename x* age3549_pop*

* do age5064_pop
rename age5064_pop x1
by fips: gen xl1=x1[_n+1]
gen dp1=(ln(xl1)-ln(x1))/12
replace dp1=dp1[_n-1] if year==2014
forvalues i=2/24 {
gen x`i'=x1*(exp((dp1)*(`i'-1)))
}
drop dp1 xl1
rename x* age5064_pop*

* do age6579_pop
rename age6579_pop x1
by fips: gen xl1=x1[_n+1]
gen dp1=(ln(xl1)-ln(x1))/12
replace dp1=dp1[_n-1] if year==2014
forvalues i=2/24 {
gen x`i'=x1*(exp((dp1)*(`i'-1)))
}
drop dp1 xl1
rename x* age6579_pop*

* do agege80_pop
rename agege80_pop x1
by fips: gen xl1=x1[_n+1]
gen dp1=(ln(xl1)-ln(x1))/12
replace dp1=dp1[_n-1] if year==2014
forvalues i=2/24 {
gen x`i'=x1*(exp((dp1)*(`i'-1)))
}
drop dp1 xl1
rename x* agege80_pop*

# delimit ;
reshape long population white_pop black_pop other_pop hispanic_pop
agele19_pop age2034_pop age3549_pop age5064_pop age6579_pop agege80_pop, i(fips year) j(month);
drop if year<2014 & month>12;
replace year=2015 if month>12;
replace month=month-12 if year==2015;

label var fips "2 digit fips code";
label var year "year";
label var month "month (1-12) of year";
label var population "state population";
label var white_pop "white population, state level";
label var black_pop "black population, state level";
label var other_pop "population of other race (not black or white), state level";
label var hispanic_pop "hispanic population, state level";
label var agele19_pop "state population <= age 19";
label var age2034_pop "state population ages 20-34";
label var age3549_pop "state population ages 35-49";
label var age5064_pop "state population ages 50-64";
label var age6579_pop "state population ages 65-79";
label var agege80_pop "state population >= 80 years of age";

*list fips year month population white_pop black_pop other_pop hispanic_pop
agele19_pop age2034_pop age3549_pop age5064_pop age6579_pop agege80_pop;
sum;
save seer_pop_month, replace;
desc;







